/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#ifndef __DYNAMICS_WORLD_H__
#define __DYNAMICS_WORLD_H__

#include "NgPrerequisites.h"

#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
#include "BulletCollision/CollisionDispatch/btCollisionConfiguration.h"
#include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
#include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h"
#include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h"

#include "TerrainObject.h"
#include "RigidGameObject.h"
#include "RigidTerrain.h"

namespace PQEngine
{
	//collision dectect plus gravity velocity...
	class DynamicsWorld
	{
	private:
		void initPhysics();
		void initTerrain();
		void initTerrainObject(TerrainObject* object);
		void initGameObject(GameObject *object);
	protected:
		btDiscreteDynamicsWorld* _dynamicsWorld;
		btConstraintSolver* _constraintSolver;
		
		btCollisionDispatcher* _dispatcher;
		btCollisionConfiguration* _collisionConfiguration;
		btBroadphaseInterface* _broadphase;
		
		DynamicsWorld();
	public:
		static DynamicsWorld& getSingleton();
		~DynamicsWorld();

		void init();	

		void addRigidBodyObject(RigidGameObject* rigidObject);

		void stepSimulation(const float elapsedTime);
		void calcContacts();
	};
}
#endif
